//
//  HLLHomeViewController.m
//  PhotoHLL
//
//  Created by mac on 2017/9/19.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#define cellIdentyfier @"homecell"
#define collettionSectionHeader @"homeheader"
#import "HLLHomeViewController.h"
#import "LB3DBannerView.h"
#import "HLLHomeCollectionViewCell.h"
@interface HLLHomeViewController ()<LB3DBannerViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) HLLNavView *navView;
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UISearchBar *searchBar;
@property (nonatomic, strong) LB3DBannerView *header1DView;
@property (nonatomic, strong) LB3DBannerView *header3DView;
@property (nonatomic, strong) NSArray *hearderArr;
@property (nonatomic, strong) NSArray *hearderArr3D;
@property (nonatomic, strong) UICollectionView *collerectionView0;

@end

@implementation HLLHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.hearderArr = @[@"https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/image/h%3D220/sign=ba3935eeb7096b639e1959523c328733/203fb80e7bec54e786aee8dfb0389b504ec26ab5.jpg",@"https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/image/h%3D220/sign=ba3935eeb7096b639e1959523c328733/203fb80e7bec54e786aee8dfb0389b504ec26ab5.jpg",@"https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/image/h%3D220/sign=ba3935eeb7096b639e1959523c328733/203fb80e7bec54e786aee8dfb0389b504ec26ab5.jpg"];
    self.hearderArr3D = @[@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1505991509164&di=729c44417d3ea97273b77a30f9e86066&imgtype=0&src=http%3A%2F%2Fpic7.nipic.com%2F20100417%2F4423485_164544037585_2.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1505991509164&di=729c44417d3ea97273b77a30f9e86066&imgtype=0&src=http%3A%2F%2Fpic7.nipic.com%2F20100417%2F4423485_164544037585_2.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1505991509164&di=729c44417d3ea97273b77a30f9e86066&imgtype=0&src=http%3A%2F%2Fpic7.nipic.com%2F20100417%2F4423485_164544037585_2.jpg"];
    
    self.navView = [[HLLNavView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 64)];
    [self.navView normalNavView];
    [self.view addSubview:self.navView];
    
    
     [self.view addSubview:self.collerectionView0];
    //    3.注册单元格（item）
    [self.collerectionView0 registerNib:[UINib nibWithNibName:@"HomeCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:cellIdentyfier];
    [self.collerectionView0 registerClass:[HLLHomeCollectionViewCell class]forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collettionSectionHeader];

    // Do any additional setup after loading the view.
}

- (UICollectionView *)collerectionView0{

    if (!_collerectionView0) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        // 1.设置列间距
        layout.minimumInteritemSpacing = 8;
        // 2.设置行间距
        layout.minimumLineSpacing = 8;
        layout.headerReferenceSize = CGSizeMake(KWidth, 650);
        //     3.设置每个item的大小
        NSInteger wide = (KWidth - 8*3)/2;
        layout.itemSize = CGSizeMake(wide, wide * 2);
        layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
        _collerectionView0 = [[UICollectionView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navView.frame), KWidth, KHeight - 64 - 55) collectionViewLayout:layout];
        _collerectionView0.backgroundColor = [UIColor clearColor];
        _collerectionView0.dataSource =self;
        _collerectionView0.delegate = self;
    }
    return _collerectionView0;
}

 
- (void)initHeaderView{

    self.headerView = [[UIView alloc] init];
    
}
- (UIView *)headerView{

    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 35 + 200)];
        [self setHeaderView];
    }
    return _headerView;
}
- (void)setHeaderView{

    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(5, 5, KWidth - 10, 35)];
    self.searchBar.placeholder = @"搜索|模特名/标签";
    self.searchBar.barStyle = UISearchBarStyleMinimal;
    self.searchBar.backgroundColor = [UIColor blackColor];
    self.searchBar.alpha = 0.3;
    self.searchBar.layer.cornerRadius = 5.0;
    self.searchBar.layer.masksToBounds = YES;
    [self.headerView addSubview:self.searchBar];
    self.header1DView = [[LB3DBannerView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.searchBar.frame) + 5, KWidth, 200) andImageURLArray:self.hearderArr andbannerWide:KWidth];
    self.header1DView.isAutoCarousel = YES;
   
    [self.headerView addSubview:self.header1DView];
    
    self.header3DView = [[LB3DBannerView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.header1DView.frame) + 5, KWidth, 400) andImageURLArray:self.hearderArr3D andbannerWide:KWidth / 10 *9];
    
    self.header3DView.delegate = self;
    self.header3DView.isAutoCarousel = YES;
    self.header3DView.carouselStarted = NO;
    self.header3DView.pageViewControl.hidden = YES;
    [self.headerView addSubview:self.header3DView];
    
    UILabel *recommendlab = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.header3DView.frame) - 28, KWidth, 21)];
    recommendlab.text = @"推荐";
    recommendlab.textAlignment = NSTextAlignmentCenter;
    [self.headerView addSubview:recommendlab];
}

#pragma mark --collectViewDeleagte
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
     
    return self.hearderArr3D.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HLLHomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentyfier forIndexPath:indexPath];
    [cell.imageView0 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.hearderArr3D[indexPath.row]]]];
    // Configure the cell
    
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    //    BackGroundCVCell *cell = (BackGroundCVCell *)[collectionView cellForItemAtIndexPath:indexPath];
    NSLog(@"选择了哪个");
}

//设置sectionHeader | sectionFoot
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        UICollectionReusableView* view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collettionSectionHeader forIndexPath:indexPath];
         
        
        [view addSubview:self.headerView];
        
        return view;
    }else{
        return nil;
    }
}

 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
